precision mediump float;

uniform vec4		realColor;
uniform vec4		lightPos;

uniform sampler2D	diffuseTex;
uniform sampler2D	specularTex;


varying vec2 uv;
varying vec4 normal;
varying vec4 vPos;


void main()
{ 
	vec4 diffuseColor	= texture2D( diffuseTex, uv );
	vec4 specularColor	= texture2D( specularTex, uv );

   
    vec4 ambient	= vec4( 0.0, 0.0, 0.0, 1 );
	vec3 nLightDir	= lightPos.xyz - vPos.xyz;

	float dist		= length( nLightDir );
	nLightDir		= normalize( nLightDir );

    vec3 n		= normalize( normal.xyz );
	float nDotL	= max( dot( n, nLightDir ), 0.0 );

    vec4 diffuse = ( diffuseColor * nDotL );

	float specular = 1.0;

	if( nDotL > 0.0 ) 
	{
        vec3 halfV		= normalize( n + nLightDir );
		float NdotHV	= max( dot( n, halfV ), 0.0 );

		float specModifier	= 75.0;
        specular = pow( NdotHV, specularColor.r * specModifier );
    }

	float radius = 100.0;
	float dForm = ( dist / radius + 1.0 );
	float attin = 1.0 / ( dForm  );
	gl_FragColor = ambient + ( diffuse * specular * attin );
}
